package com.example.common.utils

import android.view.View
import com.airbnb.lottie.LottieAnimationView
import com.example.common.R

/**
 * 动图工具类
 */
object LottieUtil {

    fun findViewId(view:View,id:Int= R.id.lottie_loading):LottieAnimationView{
        return view.findViewById<View>(id) as LottieAnimationView
    }

    /**
     * 控制显示动画/列表消失
     */
    fun startPage(lottieView:LottieAnimationView,view:View,startFun:(()->Unit)?=null){
        lottieView.visibility=View.VISIBLE
        view.visibility=View.GONE
        lottieView.playAnimation()
        if (startFun!=null){
            startFun()
        }
    }

    /**
     * 消失后动画消失/列表显示
     */
    fun endPage(lottieView:LottieAnimationView,view:View,endFun:(()->Unit)?=null){
        lottieView.visibility=View.GONE
        view.visibility=View.VISIBLE
        lottieView.cancelAnimation()
        if (endFun!=null){
            endFun()
        }
    }
}